package com.gxa.sso.routing;

import org.aspectj.lang.JoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Created by zxd on 2020/12/21
 **/
public class DataSourceAdvice {


    private Logger LOGGER=LoggerFactory.getLogger(DataSourceAdvice.class);

    public void before(JoinPoint joinPoint){

        //1.解析类上的注解  获取标记
        Class clazz = joinPoint.getTarget().getClass();
        DataSource dataSource = (DataSource) clazz.getAnnotation(DataSource.class);

        if(dataSource!=null){
            //2.放入标记到当前线程
            String value = dataSource.value();
            LOGGER.debug("current dataSource is :{}",value);
            DataSourceHolder.setDataSource(value);
        }





    }

}
